<template>
    <div class="cdgl">
        <div class="cdgl-top">
            <el-form :model="form" ref="form" label-width="80px" :inline="true" size="normal">
                <el-form-item label="菜单名称">
                    <el-input v-model="form.menuname" placeholder="请输入菜单名称"></el-input>
                </el-form-item>
            </el-form>
            <div class="top-button">
                <el-button size="default" @click="chaxun"><i class="iconfont icon-sousuo"></i> 查 询</el-button>
                <el-button size="default" @click="chongzhi"><i class="iconfont icon-sousuo"></i> 重 置</el-button>
                <el-button class="search-btn" size="default" @click="xinzeng">
                    <i class="el-icon-plus"></i>
                    新 增
                </el-button>
            </div>
        </div>
        <div class="cdgl-middle">
            <el-table class="tableBox" :data="tableData" stripe height="90%" border @selection-change="handleSelectChange"
                :row-class-name="tableRowClassName" :header-cell-style="{ background: '#b2dffe', color: '#000' }"
                style="width: 100%">
                <el-table-column prop="menuname" label="菜单名称" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="parentMenuName" label="父级菜单" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="menutype" label="菜单类型" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <span v-if="scope.row.menutype == 'M'">目录</span>
                        <span v-if="scope.row.menutype == 'C'">菜单</span>
                        <span v-if="scope.row.menutype == 'F'">按钮</span>
                    </template>
                </el-table-column>
                <el-table-column prop="ordernum" label="排序" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="操作" width="100" align="center" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <i class="el-icon-edit" title="编辑" @click="bianji(scope.row)"></i>&nbsp;
                        <i class="el-icon-delete" title="删除" @click="deleteItem(scope.row)"></i>&nbsp;
                    </template>
                </el-table-column>
            </el-table>
            <div class="bottom">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page.sync="currentPage" :page-size="pagesize" layout="total, prev, pager, next" :total="total">
                </el-pagination>
            </div>
        </div>
        <!-- 新增对话框 -->
        <el-dialog :visible.sync="xzdialogVisible" class="xzdhk" width="40%" :append-to-body="true">
            <div slot="title" class="dialog-title">
                <div class="button-right">
                    <span class="title-text">新增菜单</span>
                </div>
            </div>
            <div class="center">
                <el-form :inline="false" :model="xzform" ref="xzform" label-position="right" label-width="85px">
                    <el-form-item label="父级菜单">
                        <el-cascader v-model="xzform.parentid" :options="fjcd" :props="fjcdprop" ref="xzqh"
                            @change="xzqhorgChange" :clearable="true"></el-cascader>
                    </el-form-item>
                    <el-form-item label="菜单名称">
                        <el-input v-model="xzform.menuname" placeholder="请输入菜单名称"></el-input>
                    </el-form-item>
                    <el-form-item label="菜单类型">
                        <el-select v-model="xzform.menutype" placeholder="请选择菜单类型">
                            <el-option v-for="item in cdlx" :key="item.statusid" :label="item.statusname"
                                :value="item.statusid">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="排序">
                        <el-input v-model="xzform.ordernum" placeholder="请输入排序"></el-input>
                    </el-form-item>
                    <el-form-item label="权限标识">
                        <el-input v-model="xzform.perms" placeholder="请输入排序"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="xzdialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="addBtn">保 存</el-button>
            </span>
        </el-dialog>
        <!-- 修改对话框 -->
        <el-dialog :visible.sync="xgdialogVisible" width="40%" :append-to-body="true">
            <div slot="title" class="dialog-title">
                <div class="button-right">
                    <span class="title-text">修改角色</span>
                </div>
            </div>
            <div class="center">
                <el-form :inline="false" :model="xgform" label-position="right" label-width="85px">
                    <el-form-item label="父级菜单">
                        <el-cascader v-model="xgform.parentid" :options="fjcd1" :props="fjcdprop1" ref="xzqh"
                            @change="xzqhorgChange1" :clearable="true"></el-cascader>
                    </el-form-item>
                    <el-form-item label="菜单名称">
                        <el-input v-model="xgform.menuname" placeholder="请输入菜单名称"></el-input>
                    </el-form-item>
                    <el-form-item label="菜单类型">
                        <el-select v-model="xgform.menutype" placeholder="请选择菜单类型">
                            <el-option v-for="item in cdlx1" :key="item.statusid" :label="item.statusname"
                                :value="item.statusid">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="排序">
                        <el-input v-model="xgform.ordernum" placeholder="请输入内容"></el-input>
                    </el-form-item>
                    <el-form-item label="权限标识">
                        <el-input v-model="xgform.perms" placeholder="请输入权限标识"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="xgdialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="updateBtn">保 存</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { xtglcdgllist, xtglcdgljl, qylx, xtglcdgllistxz, xtglcdgllistsc, xtglcdgllbbj } from '@/api/index'
export default {
    data() {
        return {
            // 主页头部表单
            form: {
                menuname: '',//角色名称
            },
            // 主页表格内容
            tableData: [],
            xzdialogVisible: false,
            // 新增对话框的表单
            xzform: {
                parentid: '',//父级菜单
                menuname: '',//菜单名称
                menutype: '',//菜单类型
                ordernum: '',//排序
                perms: '',//权限标识
            },
            cdlx: [],//新增父级菜单
            cdlx1: [],//编辑父级菜单
            fjcd: [],
            xzqhprop: {
                label: "addvnm",
                value: "addvcd",
                children: "addvcds",
                checkStrictly: true,
            },
            xgdialogVisible: false,
            xgform: {
                menuid: '',//菜单id
                parentid: '',//父级菜单
                menuname: '',//菜单名称
                menutype: '',//菜单类型
                ordernum: '',//排序
                perms: '',//权限标识
            },
            ids: [],
            multipleSelection: [],
            currentPage: 1,
            pagesize: 10,
            total: 10,
            fjcd: [],//新增对话框的父级菜单
            fjcdprop: {
                label: "menuname",
                value: "menuid",
                children: "menus",
                checkStrictly: true,
            },
            fjcd1: [],//编辑对话框的父级菜单
            fjcdprop1: {
                label: "menuname",
                value: "menuid",
                children: "menus",
                checkStrictly: true,
            },
        }
    },
    mounted() {
        this.qylxobj();//获取父级菜单级联
        this.xtglcdgllist();//获取表格数据
        this.xtglcdgljl();//获取父级级联选择器
    },
    methods: {
        // 父级菜单，级联选择器
        async xtglcdgljl() {
            const res = await xtglcdgljl()
            this.fjcd = res.data.data
            this.fjcd1 = res.data.data
            // console.log(this.fjcd);
        },
        // // 获取区域类型数据
        async qylxobj() {
            // task_status
            // 获取状态数据
            const zt = 'menu_type'
            const res4 = await qylx(zt)
            // console.log(res4);
            this.cdlx = res4.data.data
            this.cdlx1 = res4.data.data
        },
        // 获取表格数据
        async xtglcdgllist() {
            const cdglobj = {
                menuName: this.form.menuname,
                pageInfo: {
                    pageIndex: this.currentPage,
                    pageSize: this.pagesize
                }
            }
            // console.log(cdglobj);
            xtglcdgllist(JSON.stringify(cdglobj)).then(res => {
                // console.log(res);
                this.tableData = res.data.data.list
                this.total = res.data.data.total
            })
        },
        // 查询
        chaxun() {
            this.xtglcdgllist()
        },
        // 重置
        chongzhi() {
            this.form.menuname = ''
            this.pagesize = 10
            this.currentPage = 1
            this.xtglcdgllist()
        },
        // 表格的隔行颜色改变
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 == 0) {
                return 'statistiss-row'
            } else {
                return ''
            }
        },
        // 父级菜单的修改
        xzqhorgChange(val) {
            this.xzform.parentid = val.slice(-1).toString();
            this.$refs.xzqh.dropDownVisible = false;
        },
        // 父级菜单的修改
        xzqhorgChange1(val) {
            this.xgform.parentid = val.slice(-1).toString();
            this.$refs.xzqh.dropDownVisible = false;
        },
        handleSizeChange() {

        },
        handleCurrentChange(val) {
            this.currentPage = val
            this.xtglcdgllist()
        },
        // 新增
        xinzeng() {
            this.mmssgg = '新增'
            this.xzdialogVisible = true
        },
        // 新增保存
        addBtn() {
            const cdglxzobj = {
                menuid: '',
                menuname: this.xzform.menuname,
                menutype: this.xzform.menutype,
                ordernum: this.xzform.ordernum,
                perms: this.xzform.perms,
                parentid: this.xzform.parentid,
                url: '',
                visible: '0'
            }
            xtglcdgllistxz(JSON.stringify(cdglxzobj)).then(res => {
                // console.log(res);
                if (res.status == 200) {
                    this.$message({
                        type: 'success',
                        duration: 3000,
                        message: '新增成功'
                    })
                    this.xtglcdgllist();
                } else {
                    this.$message({
                        type: 'error',
                        duration: 3000,
                        message: '新增失败'
                    })
                }
            })
        },
        // 编辑
        bianji(row) {
            console.log(row);
            this.xgdialogVisible = true
            this.xgform = row
            // console.log(this.xgform);
            this.xgform.menuid = row.menuid
            this.xgform.jsmc = row.jsmc
            this.xgform.beizhu = row.beizhu
        },
        // 编辑修改保存
        updateBtn() {
            const cdglxgobj = {
                menuid: this.xgform.menuid,
                menuname: this.xgform.menuname,
                menutype: this.xgform.menutype,
                ordernum: this.xgform.ordernum,
                perms: this.xgform.perms,
                parentid: this.xgform.parentid,
                url: '',
                visible: '0'
            }
            xtglcdgllbbj(JSON.stringify(cdglxgobj)).then(res => {
                if (res.status == 200) {
                    this.$message({
                        type: 'success',
                        duration: 3000,
                        message: '修改成功'
                    })
                    this.xtglcdgllist();
                } else {
                    this.$message({
                        type: 'error',
                        duration: 3000,
                        message: '修改失败'
                    })
                }
            })
        },
        // 表格里面的删除
        deleteItem(row) {
            console.log(row);
            // console.log(row.menuid);
            xtglcdgllistsc(row.menuid).then(res => {
                // console.log(res);
                if (res.status == 200) {
                    this.$message({
                        type: 'success',
                        duration: 3000,
                        message: '删除成功'
                    })
                    this.xtglcdgllist()
                } else {
                    this.$message({
                        type: 'error',
                        duration: 3000,
                        message: '删除失败'
                    })
                }
            })
        },
        // 获取多组表格内选中数据
        handleSelectChange(val) {
            // console.log(val);
            this.multipleSelection = val
            // console.log(this.multipleSelection);
        },
    },
}
</script>
<style lang="scss" scoped>
html,
body {
    height: 100%;
}

.cdgl {
    width: 100%;
    height: 100%;
    box-sizing: border-box;

    ::v-deep .cdgl-top {
        width: 97%;
        height: 10%;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        /* border: 1px solid red; */

        .el-form {
            /* width: 68%; */
            height: 100%;
            float: left;

            .el-form-item {
                padding-top: .625rem;
                padding-right: .625rem;

                .el-form-item__label {
                    background-color: #0055ab;
                    color: #fff;

                    .el-input {
                        width: 11rem;

                        .el-input__inner {
                            width: 100%;
                        }
                    }
                }

                .el-form-item__content {
                    line-height: 0;
                }
            }
        }

        .top-button {
            /* width: 32%; */
            height: 100%;
            padding-top: .625rem;
            float: right;

            .el-button {
                background-color: #0055ab;
                color: #fff;

                .iconfont {
                    font-size: .875rem;
                }
            }
        }
    }

    ::v-deep .cdgl-middle {
        width: 97%;
        height: 90%;
        margin: 0 auto;
        box-sizing: border-box;

        .el-table {
            width: 100%;
            height: 90%;
            background-color: rgb(243, 243, 243);
            padding-top: .625rem;

            .el-table__header-wrapper {}

            .el-table__body-wrapper {
                .el-icon-delete:before {
                    font-size: 1rem;
                    cursor: pointer;
                }

                .el-icon-edit {
                    cursor: pointer;
                }
            }
        }

        .bottom {
            width: 100%;
            height: 10%;

            .el-pagination {
                position: absolute;
                bottom: 3%;
                right: 6%;
            }
        }
    }
}

/deep/ .el-dialog {
    width: 40%;
    height: 60%;
    box-sizing: border-box;

    /* 查看对话框标题的大小和颜色 */
    .el-dialog__header {
        box-sizing: border-box;
        padding-bottom: 1.25rem;
        background-color: #eee;
        height: 18%;

        .dialog-title {
            .button-right {
                span {
                    font-size: 1.25rem;
                    color: #0055ab;
                }
            }
        }
    }

    .el-dialog__body {
        padding: 0 30px;
        margin-top: 20px;
        box-sizing: border-box;
        height: 56%;

        .el-form {
            width: 100%;
            height: 100%;

            .el-form-item {
                margin-bottom: .375rem;

                .el-form-item__label {

                    /* background-color: #0055ab; */
                    /* color: #fff; */
                    .el-cascader {
                        width: 100%;
                    }

                    .el-select {
                        width: 100%;
                    }
                }

                .el-form-item__content {
                    .el-input {
                        width: 100%;

                        .el-input__inner {
                            width: 100%;
                        }
                    }
                }
            }
        }
    }

    /* 查看对话框底部下载按钮 */
    .el-dialog__footer {
        width: 100%;
        height: 26%;
        text-align: center;
        box-sizing: border-box;

        .el-button {
            background-color: #0055ab;
            color: #fff;
        }
    }
}

/* 查看对话框标题的大小和颜色 */
/deep/ .dialog-title {
    .button-right {
        span {
            font-size: 20px;
            color: #0055ab;
        }
    }
}


/* 控制top表单的宽度 */
/deep/.jsgl-top .el-input {
    width: 100% !important;

    .el-input__inner {
        width: 100%;
    }
}

// 滚动条的宽度
/deep/ .el-table__body-wrapper::-webkit-scrollbar {
    width: .375rem; // 横向滚动条
    height: .125rem; // 纵向滚动条 必写
}

// 滚动条的滑块
/deep/ .el-table__body-wrapper::-webkit-scrollbar-thumb {
    background-color: #ddd;
    border-radius: .1875rem;
}

/* 表格的行高 */
/deep/ .tableBox {
    th {
        padding: 0 !important;
        height: 3.125rem;
        line-height: 3.125rem;
    }

    td {
        padding: 0 !important;
        height: 2.5rem;
        line-height: 2.5rem;
    }
}


// 鼠标经过颜色
/deep/ .el-table__body tr:hover>td {
    background-color: #d9effe !important;
}

/* 列标题的字体颜色 */
/deep/ .el-table th.el-table__cell>.cell {
    color: #000;
}

/* 内容的字体颜色 */
/deep/ .el-table--enable-row-transition .el-table__body td.el-table__cell {
    color: #000;
}

/* 表格隔行改变的颜色 */
/deep/ .el-table__row.statistiss-row {
    background-color: #f2faff;
}

/* @media all and (max-width:720px) and (min-width:320px) {

    body {

        background-color: red;

    }

    @media all and (max-width:320px) {

        body {

            background-color: blue;

        }

    }
} */
/* 去掉滚动条上方的小方块背景色 */
/deep/ .jsgl-middle .el-table--border th.el-table__cell.gutter:last-of-type {
    background: rgb(243, 243, 243);
    border: none;
}

/deep/ .el-table thead.is-group th.el-table__cell {
    background-color: #b2dffe;
}

/deep/.el-cascader {
    width: 100%;
}

/deep/.el-select {
    width: 100%;
}
</style>